//package com.service.scheduling.task;
//
//import com.service.dao.enums.RwRecordEnum;
//import com.service.dao.enums.WalletConfigEnum;
//import com.service.dao.model.RwRecord;
//import com.service.dao.model.WalletConfig;
//import com.service.scheduling.filecoin.Filecoin;
//import com.service.scheduling.filecoin.exception.ExecuteException;
//import com.service.scheduling.filecoin.exception.ParameException;
//import com.service.scheduling.filecoin.exception.SendException;
//import com.service.scheduling.filecoin.model.EasySend;
//import com.service.scheduling.filecoin.model.result.SendResult;
//import com.service.scheduling.service.RwRecordService;
//import com.service.scheduling.service.WalletConfigService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//import org.springframework.util.ObjectUtils;
//
//import java.math.BigDecimal;
//import java.math.BigInteger;
//import java.util.ArrayList;
//import java.util.List;
//
//
///**
// * 提币自动处理程序
// */
//@Slf4j
//@Component
//public class WithdrawalTask {
//
//    @Autowired
//    private RwRecordService rwRecordService;
//
//    @Autowired
//    private Filecoin filecoin;
//
//    @Autowired
//    private WalletConfigService walletConfigService;
//
//    @Scheduled(cron = "0 */10 * * * ?")
//    public void doScheduled() {
//        log.info("WithdrawalTask-doScheduled start");
//        List<RwRecord> withdrawsList  = rwRecordService.listWithdrawalFILByCoinIdAndStatus();
//        List<RwRecord> updateList = new ArrayList<>();
//        log.info("处理系统中，提币请求，审核通过，未打币的记录，opt_type = 2 and pay_status = 1");
//        if(ObjectUtils.isEmpty(withdrawsList)){
//            log.info("WithdrawalTask-doScheduled end");
//            return;
//        }else{
//            //回去FIL热钱包地址配置
//            WalletConfig walletConfig = walletConfigService.getByCoin(WalletConfigEnum.FIL_HOT.getName());
//            if(ObjectUtils.isEmpty(walletConfig)){
//                log.warn("系统未配置FIL提币热钱包信息，FIL转账失败.....");
//                return;
//            }
//            //循环处理提币订单，自动转账
//            for(RwRecord item: withdrawsList){
//                //计算转账金额
//                BigDecimal rwNum = item.getRwNum().multiply(new BigDecimal("1000000000000000000"));
//                BigInteger value = BigInteger.valueOf(rwNum.longValue());
//                try {
//                    SendResult sendResult = filecoin.easySend(EasySend.builder()
//                            .from(walletConfig.getCoinbase())
//                            .to(item.getAddress())
//                            .privatekey(walletConfig.getPrivateKey())
//                            .value(value).build());
//                    if(!ObjectUtils.isEmpty(sendResult)){
//                        String Cid = sendResult.getCid();
//                        Long nonce = sendResult.getNonce();
//                        item.setTxid(Cid);
//                        item.setPayStatus(RwRecordEnum.PayStatus.remittance.getCode());
//                        updateList.add(item);
//                    }
//                } catch (ParameException | SendException | ExecuteException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
////        int rows = rwRecordService.withdrawalERC20Usdt();
//        if(!ObjectUtils.isEmpty(updateList)){
//            rwRecordService.updateBatchById(updateList);
//        }
//        log.info("WithdrawalTask-doScheduled end");
//    }
//}
